#include "stdafx.h"
#include "Fakes/FakeD3D10Device.h"

DESCRIPTION_10_TEST_SUITE_CTOR(BufferDescription, (2, D3D10_BIND_INDEX_BUFFER))

BOOST_FIXTURE_TEST_CASE(Default, TestBufferDescription)
{
	BOOST_REQUIRE_EQUAL(2, m_desc.ByteWidth);
	BOOST_REQUIRE_EQUAL(D3D10_BIND_INDEX_BUFFER, m_desc.BindFlags);
	BOOST_REQUIRE_EQUAL(D3D10_USAGE_DEFAULT, m_desc.Usage);
	BOOST_REQUIRE_EQUAL(0, m_desc.CPUAccessFlags);
	BOOST_REQUIRE_EQUAL(0, m_desc.MiscFlags);
}

#define BUFFER_DESCRIPTION_TEST_CASE(type_, name_, value_) \
	DESCRIPTION_10_TEST_CASE(type_, name_, value_, BufferDescription)

BUFFER_DESCRIPTION_TEST_CASE(D3D10_USAGE, Usage, D3D10_USAGE_DYNAMIC)
BUFFER_DESCRIPTION_TEST_CASE(UINT, CPUAccessFlags, D3D10_CPU_ACCESS_READ)
BUFFER_DESCRIPTION_TEST_CASE(UINT, MiscFlags, D3D10_RESOURCE_MISC_SHARED)

#include "Fakes/FakeD3D10Resource.h"

class FakeD3D10Buffer : public ID3D10Buffer
{
public:
	FakeD3D10Buffer()
	{
	}

	CONTAIN_RESOURCE(Resource);

	virtual HRESULT STDMETHODCALLTYPE Map(D3D10_MAP MapType, UINT MapFlags, void **ppData) { throw rt::NotImplementedException(); }
	virtual void STDMETHODCALLTYPE Unmap() { throw rt::NotImplementedException(); }
	virtual void STDMETHODCALLTYPE GetDesc(D3D10_BUFFER_DESC *pDesc) { throw rt::NotImplementedException(); }
};

BOOST_FIXTURE_TEST_CASE(CreateNoData, TestBufferDescription)
{
	FakeD3D10Device device;
	FakeD3D10Buffer buffer;
	device.CreateBufferFakeResult = &buffer;
	device.CreateBufferFakeHResult = S_OK;
	ID3D10Buffer *result = m_desc.Create(&device, 0);
	BOOST_REQUIRE(device.CreateBufferCalled);
	BOOST_REQUIRE_EQUAL(&m_desc, device.CreateBufferLastDesc);
	BOOST_REQUIRE_EQUAL(static_cast<D3D10_SUBRESOURCE_DATA const *>(0), device.CreateBufferLastData);
	BOOST_REQUIRE_EQUAL(&buffer, result);
}

BOOST_AUTO_TEST_SUITE_END()
